package cashpointer.core.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;

/**
 * Klasa do przechowywania wlasciciela bankomatu.
 * @author wojciech topolski
 * @version 2009-03-25
 */
@XStreamAlias("Owner")
public class Owner {
    // Identyfikator wlasciciciela.
    @XStreamOmitField
    private Long id;

    // Nazwa operatora.
    @XStreamAlias("name")
    private String name;
    static private int NAME_LENGTH = 100;

    /**
     * Zwraca identyfikator wlasciciela.
     * @return Long
     */
    public Long getId() {
        return id;
    }

    /**
     * Ustawia identyfikator wlasciciela.
     * @param id Long
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Zwraca nazwe wlasciciela.
     * @return String
     */
    public String getName() {
        return name;
    }

    /**
     * Ustawia nazwe wlasciciela.
     * @param name String
     */
    public void setName(String name) {
        if (name != null) {
            this.name = (name.length() > NAME_LENGTH) ? name.substring(0, NAME_LENGTH) : name;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Owner other = (Owner) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }
}
